it = iter([1, 2, 3, 4])


def func():
    return next(it)


for j in iter(func, 4):
    print((j))

print('\r')
it = iter([1, 2, 3, 4])
for i in it:
    print(i)

# 1,2,3
# 4 是哨兵，也就是不能超过 4
print("\r")
it = iter([1, 2, 3, 4])
while True:
    try:
        # get the next item
        element = next(it)
        print(f'element:{element}')
        # do something with element
    except StopIteration:
        # if StopIteration is raised, break from loop
        print("stop iterration")
        break
"""
element:1
element:2
element:3
element:4
stop iterration
"""
